import { service } from '@/service'

enum Api {
  list = 'system/role/list',
  Edit = 'system/role',
  AllocatedList = 'system/role/authUser/allocatedList',
  Cancel = 'system/role/authUser/cancel',
  SaveOrUpdateDataScope = 'system/role/saveOrUpdateDataScope',
  GetDataScope = 'system/role/getDataScope'
}

export const roleList = (params: any) => {
  return service.request({
    url: Api.list,
    method: 'GET',
    params
  })
}

export const roleAdd = (data: any) => {
  return service.request({
    url: Api.Edit,
    method: 'POST',
    data
  })
}

export const roleDetails = (id: number) => {
  return service.request({
    url: `${Api.Edit}/${id}`,
    method: 'GET'
  })
}

export const roleEdit = (id: number, data: any) => {
  return service.request({
    url: `${Api.Edit}`,
    method: 'PUT',
    data
  })
}

export const roleDel = (ids: any[]) => {
  return service.request({
    url: `${Api.Edit}/${ids.join()}`,
    method: 'DELETE'
  })
}

// 查询已分配用户角色列表
export const roleAllocatedList = (params: any) => {
  return service.request({
    url: Api.AllocatedList,
    method: 'GET',
    params
  })
}

// 取消授权用户
export const roleCancel = (data: any) => {
  return service.request({
    url: Api.Cancel,
    method: 'PUT',
    data
  })
}

// 编辑数据权限
export const saveOrUpdateDataScope = (data: any) => {
  return service.request({
    url: Api.SaveOrUpdateDataScope,
    method: 'POST',
    data
  })
}

// 查询数据权限
export const getDataScope = (params: any) => {
  return service.request({
    url: Api.GetDataScope,
    method: 'GET',
    params
  })
}
